package com.quwan.manager.controller;

import com.quwan.app.controller.AppController;
import com.quwan.common.BaseController;
import com.quwan.common.result.ApiResult;
import com.quwan.entity.TSpreadProfitList;
import com.quwan.entity.TSpreadSetting;
import com.quwan.manager.service.SpreadSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author quan
 * @date 2021-10-25 15:24
 */

@Api(tags = "推广配置")
@RestController
@RequiredArgsConstructor
@RequestMapping("mgr/spreadSetting")
public class SpreadSettingController extends BaseController {
    private final SpreadSettingService spreadSettingService;

    @ApiOperation("配置开关")
    @GetMapping("/switch")
    public ApiResult<Boolean> switchButton() {
        AppController.SPREADSETTINGOFF=!AppController.SPREADSETTINGOFF;
        System.out.println(AppController.SPREADSETTINGOFF);
        return ApiResult.success(AppController.SPREADSETTINGOFF);
    }

    @ApiOperation("配置列表")
    @GetMapping("/list")
    public ApiResult<List<TSpreadSetting>> spreadSettingList() {
        return ApiResult.success(spreadSettingService.getSpreadSettingList());
    }

    @ApiOperation("盈利榜单自定义数据列表")
    @GetMapping("/profitList")
    public ApiResult<List<TSpreadProfitList>> proditList() {
        return ApiResult.success(spreadSettingService.getProfitList());
    }

    @ApiOperation("添加配置")
    @PostMapping("/add")
    public ApiResult<String> add(TSpreadSetting params) {
        if (spreadSettingService.addSetting(params))
            return ApiResult.success();

        return ApiResult.failed();
    }

    @ApiOperation("添加盈利榜单数据")
    @PostMapping("/addProfitList")
    public ApiResult<String> addProfitList(TSpreadProfitList params) {
        if (spreadSettingService.addProfitList(params))
            return ApiResult.success();

        return ApiResult.failed();
    }

    @ApiOperation("删除配置")
    @PostMapping("/del")
    public ApiResult<String> del(String id) {
        if (spreadSettingService.delSetting(id))
            return ApiResult.success();

        return ApiResult.failed();
    }

    @ApiOperation("删除盈利榜单数据")
    @PostMapping("/delProfitList")
    public ApiResult<String> delProfitList(String id) {
        if (spreadSettingService.delProfitList(id))
            return ApiResult.success();

        return ApiResult.failed();
    }


}
